package com.gmail.blackdog1987.onedollar.util;

import com.gmail.blackdog1987.onedollar.entity.ResultJson;
import com.gmail.blackdog1987.onedollar.entity.base.Page;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LuckyBagUtil {

	public static double [] generateLuckyBagConsume(double total_money, int total_people){
		double min_money = 0.01;
		double [] resule = new double[total_people];
		for (int i = 0; i < total_people - 1; i++) {
			int j = i + 1;
			double safe_money = (total_money - (total_people - j) * min_money)
					/ (total_people - j);
			double tmp_money = (Math.random()
					* (safe_money * 100 - min_money * 100) + min_money * 100) / 100;

			BigDecimal b = new BigDecimal(tmp_money);
			tmp_money = b.setScale(2, BigDecimal.ROUND_UP).doubleValue();

			total_money = new BigDecimal(total_money).subtract(new BigDecimal(tmp_money)).doubleValue();
			resule[i] = tmp_money;
			System.out.format("第 %d 个红包： %.2f 元，剩下： %.2f 元\n", j, tmp_money,
					total_money);
		}

		BigDecimal b = new BigDecimal(total_money);
		resule[total_people-1] = b.setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();

		return resule;
	}

	public static void main(String[] args){
		double[] tmp = generateLuckyBagConsume(100.0, 1);
		for(int i = 0; i < 1; i++){
			System.out.println(tmp[i]);
		}
	}
}
